const router = require('koa-router')(),
  moment=require('moment')
  essay=require('../models/essay');

router.prefix('/essay')

router.get('/byname', async function (ctx, next) {
    const {name}=ctx.query
    ctx.body=await essay.getEssayByName(name);
})

router.get('/byuser', async function (ctx, next) {
  const {userid}=ctx.query
  ctx.body=await essay.getEssayByUser(userid);
})

router.get('/upload', async function (ctx, next) {
  const {id,title,content,date}=ctx.query
  ctx.body=await essay.getEssayUpload(id,title,content,date);
})

router.get('/uploadpics', async function (ctx, next) {
  const {id,path}=ctx.query
  console.log(id,path)
  ctx.body=await essay.getEssayPics(id,path);
})

router.get('/del', async function (ctx, next) {
  const {id}=ctx.query
  console.log(id)
  ctx.body=await essay.delEssay(id)
})

router.get('/getstate',async function (ctx,next){
  const {id}=ctx.query
  ctx.body=await essay.getState(id)
})
module.exports = router